<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>string对象</title>
</head>
<body>
    <script>
        //创建
        var s1 = new String("hello");
        var s2 = "world";
        console.log(s2.length);//5
        //在字符串中查找字符
        console.log(s2.indexOf("o"));//1
        console.log(s2.lastIndexOf("o"));//1
        //返回字符的位置
        console.log(s2.charAt(2));//r
        console.log(s2.charCodeAt(2));//114,国际字符编码
        //截取字符串
        console.log(s2.slice(1,3));//or 如果需要处理负数索引
        console.log(s2.substring(1,3)); //or
        //替换
        console.log(s2.replace("o","a"));//warld
        //分割
        console.log(s2.split("o"));//Array [ "w", "rld" ]
        //拼接
        console.log(s2.concat("!","!","!"));
    </script>
    
</body>
</html>